package com.foreknow.homework1009.worker;

public class Method {
    Worker[] workers = new Worker[5];

    public void add(Worker worker) {
        for (int i = 0; i < workers.length; i++) {
            if (workers[i] == null) {
                workers[i] = worker;
                break;
            }
        }
    }

    public void delete(int id) {
        for (int i = 0; i < workers.length; i++) {
            if (workers[i].getId() == id) {
                workers[i] = null;
                break;
            }
        }
    }

    public void query(int id) {
        System.out.println("--------------------------");
        for (int i = 0; i < workers.length; i++) {
            if (workers[i]!=null){
                if (workers[i].getId() == id) {
                    System.out.println(workers[i].getId()+"   "+workers[i].getName()+"   "+workers[i].getSex());
                    break;
                }
            }else {
                continue;
            }
        }
        System.out.println("--------------------------");
    }

    public void queryAll() {
        System.out.println("--------------------------");
        for (int i = 0; i < workers.length; i++) {
            if (workers[i]!=null){
                System.out.println(workers[i].getId()+"   "+workers[i].getName()+"   "+workers[i].getSex());
            }else {
                System.out.println("null");
            }
        }
        System.out.println("--------------------------");
    }
}
